package com.appheader.rongmaphone.utils;

import android.content.Context;
import android.view.Display;
import android.view.WindowManager;

/**
 * Created by zhep on 2016/10/26.
 */
public class ScreenUtils {
//    private  static float density = 0;
//    public static float itemWidth=0;
    /**
     * 获取屏幕宽度
     */
    public static int getScreenWidth(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getWidth();
    }

    public static int getScreenHeight(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getHeight();
    }
    public static int Dp2Px(Context context, float dp) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dp * scale + 0.5f);
    }
//    public static int dipToPx(Context context, int dip) {
//        if(density <= 0.0F) {
//            density = context.getResources().getDisplayMetrics().density;
//        }
//
//        return (int)((float)dip * density + 0.5F);
//    }
}
